<?php
/**
 * 名称：UserAction
 * 描述：后台用户管理
 * 作者：jepin 时间：2014-11-14
 * 版本号：V1.0.0
 * ========================历史版本=================================
 * 序号	 版本号 	日期			姓名	 	描述
 * 1 	V1.0.0 	2014-11-14	jepin  	蜘蛛寻记录
 * ========================历史版本=================================
 * 说明：请在有更改程序的时候修改以上注释
 */
class SearcherAction extends CommonAction {
	public function index() {
	}
	public   $site="";
	function preg($keyword,$text_from)
	{
		preg_match_all( $keyword,$text_from, $text );
		return $text;
	}
	
	function fop($page_url)
	{
		$text="";
		$f = @fopen( $page_url, 'r' );
		while( $data = @fread( $f, 1024) ) { $text.= $data; }
		@fclose( $f );
		return $text;
	}
	
	public function test(){
		  $str=strtotime('2014-11-21');
		echo  date('Ym',time());
	}
	
	public function  searcher(){
		//$filename =$_GET['filename'];
		$sTime    =$_GET['sTime'];
		$site    =$_GET['site'];
		$keyword  =$_GET['keyword'];
		$code     =$_GET['code'];
		$searcher =$_GET['searcher'];
		$pagenum  =intval($_GET['pagenum']) ;
		if($pagenum==0){
			$pagenum =100;
		}
		$this->assign('pagenum',(string)$pagenum);
		if(!empty($code)){
           $this->assign('code',$code);			 
		}
		if(!empty($keyword)){
			$this->assign('keyword',$keyword);	
		}
		if(!empty($searcher)){
			$this->assign('searcher',$searcher);
		}
		if(!empty($site)){
			$this->site=$site;
			$this->assign('site',$site);
		}else{
			 $site='i8i8i8.com';
			 $this->site=$site;
			//$site='access';
			$this->assign('site',$site);
		}
	    if(($site=="i8i8i8.com")||($site=="baby.i8i8i8.com")||($site=="wed.i8i8i8.com")||($site=="travel.i8i8i8.com")||($site=="api.i8i8i8.com")){
	    	$filename='http://logs2.i8i8i8.cn/';
	    }else{
	    	$filename='http://logs.i8i8i8.cn/';
	    }
		if((empty($sTime)||($sTime==date('Y-m-d',time())))){
		 $filename.=$site.'.log';
		 $this->assign('sTime',date('Y-m-d',time()));
		}else{
			$time=strtotime($sTime);
			$filename.=date('Y/m',$time).'/'.$site.'_'.date('Ymd',$time).'.log';
			$this->assign('sTime',$sTime);
		}
		$data = array();
		//echo $filename;
		 // $filename ='D:\i8i8i8.com.log';
		$fh = @fopen($filename, 'r');
		$i=0;
	    $pstart =$_GET['p']? $_GET['p']:0;
		$pstart=$pstart*$pagenum;
		$pend=$pstart +$pagenum;
		if ($fh) {
			while (! feof($fh)) {
				$row = fgets($fh, 4096);
				$row_arr = explode(" ", $row);
				$temp =$row;
				if(!empty($code)){
					if($code!=$row_arr[8]){
						continue;
					}
				}
				if(!empty($keyword)){
					if(false===strpos($temp,$keyword)){
						continue;
					}
				}
				if(!empty($searcher)){
					if(false===strpos($temp,$searcher)){
						continue;
					}
				}
				
				if(($i>=$pstart)&&($i<$pend)){
				 
					$data[]=$temp;
				}
				$i++;
			}
		}
		fclose($fh);
		import ( "ORG.Util.Page" );
		//$count =count($data );
		$count=$i;
		$p = new Page ( $count, $pagenum );
		$page = $p->show ();
		//$temp= array_slice($data,$p->firstRow,$p->firstRow+$pagenum,true);
		$list =array();
		foreach ($data as $v){
			$list[]=$this->format($v);
		}
		$this->assign('page', $page );
		$this->assign('list',$list);
		$this->display();
	}
	
    private function format($linedata){
  	   $arr =explode(" ", $linedata) ;
  	   $data['remoteip'] = $arr[0];
  	   $data['user'] = $arr[1];
  	   $data['username'] = $arr[2];
  	   $data['time'] = $arr[3].$arr[4];
  	  // $arr[6]= substr($arr[6],1);
  	   if(true==strpos($arr[6],'note')){
  	   	$arr[6]='http://like.i8i8i8.com'.$arr[6];
  	   }
       if(false===strpos($arr[6],'http:')){
       	 if(empty($this->site)){
       	    $data1= M()->query('  SELECT domain from '.$this->_dbPrefix.'cms_site  where siteid =1');
       	    $this->site=$data1[0]['domain'];
       	    $arr[6]='http://'.$data1[0]['domain']. $arr[6];
       	 }else{
         	 $arr[6]='http://'.$this->site. $arr[6];
       	 }
	   }
	   if(true==strpos($arr[6],'/?src=')){
	     $arr[6]= str_replace('/?src=', "", $arr[6]);
	   }
	  
  	   $data['url'] = $arr[6];//substr($arr[6],1);
  	   $data['code'] = $arr[8];
  	   $arr[10] =substr($arr[10], 1,strlen($arr[10])-2);
  	   $data['from'] =$arr[10];
  	   return $data;
  }
}

?>